package com.humi.partner.front.service;
import	java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.humi.cloud.common.model.Result;
import com.humi.cloud.mybatis.support.model.Page;
import com.humi.cloud.security.support.utils.SecurityUtil;
import com.humi.partner.common.dict.PartnerBaseStatus;
import com.humi.partner.common.entity.PartnerBase;
import com.humi.partner.common.entity.PartnerType;
import com.humi.partner.common.service.PartnerBaseService;
import com.humi.partner.common.service.PartnerTypeService;
import com.humi.partner.front.dao.FrontPartnerTypeMapper;
import com.humi.partner.front.model.partnerType.PartnerTypeListQueryRequest;
import com.humi.partner.front.model.partnerType.PartnerTypeListQueryResponse;
import com.humi.partner.manager.dao.ManagerPartnerTypeMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * <pre>
 * @Auther: lishijie
 * @Date: 2019/10/24 09:08
 *   Ver   		Date                    Author               	 Detail
 *   ----------------------------------------------------------------------
 *   1.0     2019/10/24 09:08    lishijie@360humi.com        new file.
 * @Description:Codes
 * </pre>
 */
@Service
public class FrontPartnerTypeService extends ServiceImpl<ManagerPartnerTypeMapper,PartnerType> {
    @Autowired
    PartnerTypeService partnerTypeService;

    @Autowired
    PartnerBaseService partnerBaseService;

    @Autowired
    FrontPartnerTypeMapper frontPartnerTypeMapper;


    /**
     * 查询伙伴类型信息
     * @param
     * @return
     */
    public Result getPertnerType(){
        Result result = new Result();
        List<PartnerType> list = this.list();
        if(list != null && !list.isEmpty()){
            result.setData(list);
        }
        return result;
    }



    /**
     * 获取指定伙伴类型的申请状态
     * @param partnerTypeId  伙伴类型ID
     * @return
     */
    public Result getApplyStatus(String partnerTypeId){
        if (StringUtils.isBlank(partnerTypeId)){
            return Result.fail("参数不能为空");
        }
        String userId = SecurityUtil.getUser().getSourceId();
        PartnerBase partnerBase = this.partnerBaseService.getOne(new LambdaQueryWrapper<PartnerBase>().eq(PartnerBase::getApplyType, partnerTypeId).eq(PartnerBase::getUserId, userId));
        Result result = new Result();
        if (null != partnerBase ){
            return Result.ok("查询成功",PartnerBaseStatus.format(partnerBase.getApplyStatus()).getCode());
        }
        result.setData("");
        return result;
    }


}
